<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>
    <el-tabs class="login-tabs" type="border-card" stretch v-model="currentTab">
      <el-tab-pane name="account">
        <template #label>
          <span><el-icon><avatar /></el-icon>账号登录</span>
        </template>
        <login-account ref="accountRef"/>
      </el-tab-pane>
    <el-tab-pane name="phone">
        <template #label>
          <span><el-icon><cellphone /></el-icon>手机登录</span>
        </template>
        <login-phone ref="phoneRef"/>
      </el-tab-pane>
    </el-tabs>
    <div class="account-control">
      <el-checkbox v-model="isKeepPassword">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button type="primary" class="login-btn" @click="handleLoginClick">立即登录</el-button>
  </div>
</template>

<script lang="ts">
import { defineComponent , ref} from "vue";
import { Avatar,  Cellphone} from '@element-plus/icons';
import LoginAccount from './login-account.vue';
import LoginPhone from './login-phone.vue'

export default defineComponent({
  components:{
    Avatar,
    Cellphone,
    LoginAccount,
    LoginPhone,
  },
  setup() {
    const isKeepPassword = ref(true)
    const accountRef = ref<InstanceType<typeof LoginAccount>>()
    const phoneRef = ref<InstanceType<typeof LoginPhone>>()
    const currentTab = ref<string>('account')

    const handleLoginClick = () => {
      // console.log('点击了登录')
      if(currentTab.value === 'account'){
        //表示账号登录
         accountRef.value?.loginAction(isKeepPassword.value)
      }else{
        //手机登录
        // console.log('手机登录')
         phoneRef.value?.loginAction()
      }

    }
    return {
      isKeepPassword,
      handleLoginClick,
      accountRef,
      phoneRef,
      currentTab,
    }
  }
})
</script>

<style lang="less" scoped>
.login-panel{
  width: 320px;
  margin-top: -150px;
  .title{
    text-align: center;
  }
  .account-control{
    display: flex;
    justify-content: space-between;
  }
  .login-btn{
    width: 100%;
    // margin-top: 50px;
  }
  .login-tabs{
    height: 220px;
  }
}
</style>
